package vista;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class VentanaListaProducto extends javax.swing.JFrame {
	private JScrollPane jScrollPane1;
	private JButton jButton1;
	private JButton jbBuscar;
	private JLabel lblimagen;
	private JPanel pnlLista;
	private JTable jTProducto;
	private JButton jbEliminar;
	private JButton jButton2;
	private JLabel jLabel1;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	

	public VentanaListaProducto() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			{
				pnlLista = new JPanel();
				getContentPane().add(pnlLista, BorderLayout.CENTER);
				pnlLista.setLayout(null);
				pnlLista.setPreferredSize(new java.awt.Dimension(644, 462));
				pnlLista.setBackground(new java.awt.Color(255, 255, 255));
				pnlLista.setSize(93, 31);
				{
					jLabel1 = new JLabel();
					pnlLista.add(jLabel1);
					jLabel1.setText("Listas de Producto");
					jLabel1.setBounds(210, 18, 232, 27);
					jLabel1.setFont(new java.awt.Font("Bitstream Charter", 0,
							20));
				}
				{
					jScrollPane1 = new JScrollPane();
					pnlLista.add(jScrollPane1);
					jScrollPane1.setBounds(86, 74, 489, 280);
					jScrollPane1
							.setBackground(new java.awt.Color(255, 255, 255));
					{
						DefaultTableModel jTProductoModel = new DefaultTableModel(
								new String[][] {}, new String[] { "Codigo ",
										"Nombre", "Linea", "Presentacion" }) {
							@Override
							public boolean isCellEditable(int row, int column) {
								return false;
							}
						};
						jTProducto = new JTable();
						jScrollPane1.setViewportView(jTProducto);
						jTProducto.setModel(jTProductoModel);
						jTProducto
								.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
					}
				}
				{
					jbEliminar = new JButton();
					pnlLista.add(jbEliminar);
					jbEliminar.setBounds(363, 381, 93, 31);
					jbEliminar.setActionCommand("Eliminar");
					jbEliminar.setBorder(BorderFactory.createEmptyBorder(0, 0,
							0, 0));
					jbEliminar.setIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Eliminar2.jpg")));
					jbEliminar.setRolloverIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Eliminar.jpg")));
				}
				{
					jButton2 = new JButton();
					pnlLista.add(jButton2);
					jButton2.setBounds(236, 386, 93, 31);
					jButton2.setActionCommand("Modificar");
					jButton2.setIcon(new ImageIcon(getClass().getClassLoader()
							.getResource("imagen/Boton_Modifi2.jpg")));
					jButton2.setSelected(true);
					jButton2.setRequestFocusEnabled(false);
					jButton2.setRolloverIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Modifi.jpg")));
					jButton2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
							0));
				}
				{
					jButton1 = new JButton();
					pnlLista.add(jButton1);
					jButton1.setBounds(103, 381, 93, 31);
					jButton1.setActionCommand("Incluir");
					jButton1.setIcon(new ImageIcon(getClass().getClassLoader()
							.getResource("imagen/Boton_Incluir2.jpg")));
					jButton1.setRolloverIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Incluir.jpg")));
					jButton1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
							0));
				}
				{
					lblimagen = new JLabel();
					lblimagen.setLayout(null);
					pnlLista.add(lblimagen);
					pnlLista.add(getJbBuscar());
					lblimagen.setBounds(0, 51, 52, 406);
					lblimagen.setIcon(new ImageIcon(getClass().getClassLoader()
							.getResource("imagen/fondo7.jpg")));
				}
			}
			pack();
			this.setSize(612, 452);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

	public void agregarListener(ActionListener accion) {

		jbEliminar.addActionListener(accion);
		jButton2.addActionListener(accion);
		jButton1.addActionListener(accion);
		jbBuscar.addActionListener(accion);
	}

	public void setListado(AbstractTableModel abstractTableModel) {
		jTProducto.setModel(abstractTableModel);
	}

	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public int getCantidadFilasTbProducto() {
		return this.jTProducto.getRowCount();
	}

	public int getFilaSeleccionada() {

		return this.jTProducto.getSelectedRow();
	}

	public void agregarFilaProducto(Vector<String> datoProducto) {
		DefaultTableModel modelop = (DefaultTableModel) this.jTProducto
				.getModel();

		modelop.addRow(datoProducto);

	}

	public String obtenerCodigoProductoFilaSeleccionada() {
		int fila = jTProducto.getSelectedRow();
		String codigoProducto = (String) jTProducto.getModel().getValueAt(fila,
				0);
		return codigoProducto;
	}

	public int numeroFilasSeleccionadas() {
		return jTProducto.getSelectedRowCount();
	}

	private JButton getJbBuscar() {
		if (jbBuscar == null) {
			jbBuscar = new JButton();
			jbBuscar.setBounds(482, 381, 93, 31);
			jbBuscar.setIcon(new ImageIcon(getClass().getClassLoader()
					.getResource("imagen/Boton_Buscar2.jpg")));
			jbBuscar.setRolloverIcon(new ImageIcon(getClass().getClassLoader()
					.getResource("imagen/Boton_Buscar.jpg")));
			jbBuscar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
			jbBuscar.setActionCommand("Buscar");
		}
		return jbBuscar;
	}

	public void eliminarFilaSeleccionada(int i) {

		DefaultTableModel modelo = (DefaultTableModel) this.jTProducto
				.getModel();

		modelo.removeRow(i);

	}

}
